﻿@model SMECustomerWebsite.Models.ViewModels.SalePerformance.SaleContestRankingViewModel
@Html.Action("SubMenuSaleContestRanking", "System")
<div class="row">
    <div class="col-md-12">
        <div class="x_panel">
            <div class="x_title">
                <div class="col-lg-8 col-md-9 col-sm-8">
                    @Html.Action("SubMenuSaleContestRankingBack", "System")
                    <h2 class="col-lg-8">@SMECustomerWebsite.Core.Resources.Resource.SaleContestPersonRanking @Model.SaleContestRecord.SaleContestName</h2>
                </div>
                <ul class="nav navbar-right panel_toolbox">
                    @Html.Action("BusinessDateInfo", "System", new { name = "TBL_SALE_CONTEST_BIL_AWARD_RAW" })
                    <li>
                        <a class="collapse-link"><i class="fa fa-chevron-up"></i></a>
                    </li>
                </ul>
                <div class="clearfix"></div>
            </div>
            <div class="x_content">
                <div class="col-md-6 cm-search-box">
                    <a href="/ProductHandbook/SaleContestInfo?salecontest=@Request.QueryString["salecontest"]" class="btn btn-success right sme-form-export">Xem thông tin chương trình</a>
                </div>
                @switch (Model.DaoInfo.GroupIdentifier)
                {
                    case "1":
                        <table id="sp-deposit" class="table table-bordered table-striped jambo_table custom_table" style="width:100% !important">
                            <thead class="headings">
                                <tr>
                                    <th class="column-title">@SMECustomerWebsite.Core.Resources.Resource.Zone.ToUpper()</th>
                                    <th class="column-title">@SMECustomerWebsite.Core.Resources.Resource.RankHeader</th>
                                    <th class="column-title">@SMECustomerWebsite.Core.Resources.Resource.Branch.ToUpper()</th>
                                    <th class="column-title">DAO</th>
                                    <th class="column-title">@SMECustomerWebsite.Core.Resources.Resource.MSBONameHeader</th>
                                    <th class="column-title">@SMECustomerWebsite.Core.Resources.Resource.EligbelSaleContestHeader</th>
                                    <th class="column-title">Mức đạt</th>
                                </tr>
                            </thead>
                            <tbody></tbody>
                        </table>
                        break;
                    case "2":
                    <table id="sp-deposit" class="table table-bordered table-striped jambo_table custom_table" style="width:100% !important">
                        <thead class="headings">
                            <tr>
                                <th class="column-title">@SMECustomerWebsite.Core.Resources.Resource.RankHeader</th>
                                <th class="column-title">@SMECustomerWebsite.Core.Resources.Resource.Branch.ToUpper()</th>
                                <th class="column-title">DAO</th>
                                <th class="column-title">@SMECustomerWebsite.Core.Resources.Resource.MSBONameHeader</th>
                                <th class="column-title">@SMECustomerWebsite.Core.Resources.Resource.EligbelSaleContestHeader</th>
                                <th class="column-title">Mức đạt</th>
                            </tr>
                        </thead>
                        <tbody></tbody>
                    </table>
                        break;
                    case "3":
                    <table id="sp-deposit" class="table table-bordered table-striped jambo_table custom_table" style="width:100% !important">
                        <thead class="headings">
                            <tr>
                                <th class="column-title">@SMECustomerWebsite.Core.Resources.Resource.RankHeader</th>
                                <th class="column-title">DAO</th>
                                <th class="column-title">@SMECustomerWebsite.Core.Resources.Resource.MSBONameHeader</th>
                                <th class="column-title">@SMECustomerWebsite.Core.Resources.Resource.EligbelSaleContestHeader</th>
                                <th class="column-title">Mức đạt</th>
                            </tr>
                        </thead>
                        <tbody></tbody>
                    </table>
                        break;
                    case "4":
                    <table id="sp-deposit" class="table table-bordered table-striped jambo_table custom_table" style="width:100% !important">
                        <thead class="headings">
                            <tr>
                                <th class="column-title">@SMECustomerWebsite.Core.Resources.Resource.RankHeader</th>
                                <th class="column-title">DAO</th>
                                <th class="column-title">@SMECustomerWebsite.Core.Resources.Resource.MSBONameHeader</th>
                                <th class="column-title">@SMECustomerWebsite.Core.Resources.Resource.EligbelSaleContestHeader</th>
                                <th class="column-title">Mức đạt</th>
                            </tr>
                        </thead>
                        <tbody></tbody>
                    </table>
                        break;
                    default:
                        break;
                }
                @Html.Partial("SaleContestSumary", Model.SaleContestRecord)
            </div>
        </div>
    </div>
</div>

@section scripts
{
    <script src="~/Scripts/tableeditable/dataTables.rowsGroup.js"></script>
    <script type="text/javascript">
        $(document).ready(function () {
            var totalColumn = [
                        { "sName": "CIF", "className": 'column-title', "bSortable": false },
                        { "sName": "NAME", "bSortable": false },
                        { "sName": "VPB INDUSTRY", "bSortable": false },
                        { "sName": "DATE OPEN", "className": 'column-title', "bSortable": false },
                        { "sName": "CUSTOMER STATUS", "bSortable": false }]
            var totalLenCol = 4;
            var DaoCol = 1;
            switch (@Model.DaoInfo.GroupIdentifier)
            {
                case 1:
                    totalColumn = [
                           { "sName": "REGION", "className": 'column-title', "bSortable": false },
                           { "sName": "BRANCH", "className": 'column-title', "bSortable": false },
                           { "sName": "DAO", "bSortable": false },
                           { "sName": "MSBO", "bSortable": false },
                           { "sName": "CIF", "bSortable": false },
                           { "sName": "NAME", "className": 'column-title', "bSortable": false },
                           { "sName": "VPB INDUSTRY", "bSortable": false }];
                    totalLenCol = 6;
                    DaoCol = 3;
                    break;
                case 2:
                    totalColumn=  [
                        { "sName": "BRANCH", "className": 'column-title', "bSortable": false },
                        { "sName": "BRANCH", "bSortable": false },
                        { "sName": "DAO", "bSortable": false },
                        { "sName": "MSBO", "bSortable": false },
                        { "sName": "CIF", "className": 'column-title', "bSortable": false },
                        { "sName": "NAME", "bSortable": false }];
                    totalLenCol = 5;
                    DaoCol = 2;
                    break;
                case 3:
                    totalColumn= [
                        { "sName": "DAO", "className": 'column-title', "bSortable": false },
                        { "sName": "MSBO", "bSortable": false },
                        { "sName": "CIF", "bSortable": false },
                        { "sName": "NAME", "className": 'column-title', "bSortable": false },
                        { "sName": "VPB INDUSTRY", "bSortable": false }];
                    totalLenCol = 4;
                    DaoCol = 1;
                    break;
                default:
                    break;
            }

            var table = $('#sp-deposit').DataTable({
                "order": [[0, 'asc']],
                "bServerSide": true,
                "bProcessing": true,
                "responsive": true,
                "bAutoWidth": false,
                "aLengthMenu": [10, 30, 50, 100],
                "pageLength": 10,
                rowsGroup: [0],
                //"bProcessing": true,
                "sAjaxSource": '@Url.Action("SaleContestRankingMSBOData", "SalePerformance")' + '?salecontest=@Request.QueryString["salecontest"]',
                "fnServerData": function (sSource, aoData, fnCallback) {
                    $.ajax({
                        "dataType": 'json',
                        "type": "POST",
                        "url": sSource,
                        "data": aoData,
                        "success": fnCallback
                    });
                },
                "sDom": "<'row-fluid'<'span6'l><'span6'f>r>t<'row-fluid'<'dataTables_wrapper'ip>>",
                "aoColumns": totalColumn,
                "aoColumnDefs": [
                    {
                        "aTargets": [DaoCol+1],
                        "mRender": function (data, type, full) {
                            if (full[totalLenCol+1] == '') {
                                return data;
                            } else {
                                return '<a href="' + full[totalLenCol+1] + '?dao='+full[DaoCol]+'">' + data + '</a>';
                            }

                        }
                    }
                ],
                "drawCallback": function (settings) {
                    $('table.custom_table th').removeClass().addClass('column-title');
                }
            });

        });
    </script>
}